<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\assets\CropperAsset;
use app\models\Helpers;
use app\modules\clinical\models\Check;

/* @var $this yii\web\View */
/* @var $model app\models\Check */
/* @var $form yii\widgets\ActiveForm */

CropperAsset::register($this);
$this->registerCssFile("/css/cropper.css");
$this->registerJsFile("/js/pic.js", ['depends' => 'yii\web\JqueryAsset']);
$this->registerJsFile('@web/js/check.js', ['depends' => 'app\assets\AppAsset']);

$pic = Helpers::checkExist("check", empty($model->pic_id) ? 'xxx' : $model->pic_id);
?>

<div class="check-form myForm">

    <div class="alert alert-danger" id="error-msg"></div>

    <?php $form = ActiveForm::begin([
        'method' => 'post',
        'action' => $model->isNewRecord ? '/clinical/check/create' : 'update?id='.$model->pk_id,
        'id' => 'checkForm'
    ]); ?>

    <div class="form-group">
      <?= Html::label('患者姓名', 'pt_rel') ?><br />
      <?= Html::dropDownList('pt_rel', !empty($pt_rel) ? $pt_rel : 0, $pt_rel_list, ($model->isNewRecord) ? ['class' => 'pt_rel_list'] : ['class' => 'pt_rel_list', 'disabled' => 'true']) ?>
    </div>

    <?= $form->field($model, 'ck_type')->dropDownList(Check::getParams('check_type')) ?><br />

    <?= $form->field($model, 'ck_program')->dropDownList(Check::getParams('ck_program')) ?>

    <?= $form->field($model, 'ck_date')->textInput(['class'=>'form-control laydate-icon date'])->error(false) ?><br />

    <?= $form->field($model, 'ck_result', ['labelOptions' => ['class' => 'lg_area']])->textarea(['maxlength' => true])->error(false) ?><br />

    <?php if ($model->ck_type == '' || $model->ck_type == 'lab') : ?>
    
    <?= $form->field($model, 'ck_range')->textInput(['maxlength' => true])->error(false) ?>

    <?= $form->field($model, 'ck_unit')->textInput(['maxlength' => true])->error(false) ?><br />

    <?php endif; ?>

    <div class="crop-avatar">
        <b>上传图片：</b><br />
        <?= HTML::button('添加图片', ['class' => 'btn btn-default avatar-view']) ?>
        <?= HTML::a('查看图片', $pic['href'], ['class' => 'btn btn-default', 'target' => '_blank']) ?>
        <input type="hidden" id="pic-name" value="check">
        <img <?= $pic['name'] ?> id="upload-pic">
    </div><br /><br />

    <input type="hidden" name="Check[pic_id]" value="<?= $model->pic_id ?>">
    <input type="hidden" id="status" value="<?= $model->isNewRecord ? 'create' : 'update?id='.$model->pk_id ?>">
    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? '保存' : '更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary', 'id' => 'submitButton']) ?>

        <?= Html::a('取消', ['/clinical/check'], ['class' => 'btn btn-success']) ?>
    </div>

    <?php ActiveForm::end(); ?>

    <div class="crop-avatar">
      <?= $this->render('@app/views/layouts/media.php') ?>
    </div>

</div>
